import chartsRouter from './modules/charts'
import loadable from '@loadable/component'

export const constantRoutes = [
//   {
//     path: '/redirect',
//     component: '',
//     hidden: true,
//     children: [
//       {
//         path: '/redirect/:path(.*)',
//         component: () => import('@/components/Home/Home.jsx')
//       }
//     ]
//   },
  {
    path: '/login',
    component: loadable(() => import('@/pages/Login/Login.jsx')),
  },
  {
    path: '/404',
    component: loadable(() => import('@/pages/404/404.jsx')),
  },
  {
    path: '/401',
    component: loadable(() => import('@/pages/401/401.jsx')),
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/',
    component: '',
    redirect: '/dashboard/index',
    meta: {
        title: 'Dashboards',
        icon: 'lock',
        authority: ['admin','editor']
      },
    children: [
      {
        path: '/dashboard/index',
        component: loadable(() => import('@/components/Home/Home.jsx')),
        name: 'Dashboard',
        meta: { title: 'Dashboard', icon: 'dashboard', affix: true,  authority: ['editor'] }
      },
      {
        path: '/dashboard2/index',
        component: '',
        name: 'Dashboard',
        meta: { title: 'Dashboard2', icon: 'dashboard', affix: true, authority: ['admin'] }
      }
    ]
  },
  {
    path: '/guide',
    component: '',
    redirect: '/guide/guide-index',
    meta: {
        title: 'guide',
        icon: 'lock',
        authority: ['admin']
      },
    children: [
      {
        path: '/guide/guide-index',
        component: '',
        name: 'Guide',
        meta: { title: 'Guide', icon: 'guide', noCache: true, authority: ['admin'] }
      }
    ]
  },
  {
    path: '/profile',
    component: '',
    redirect: '/profile/profile-index',
    meta: {
        title: 'profile',
        icon: 'lock',
        authority: ['editor']
      },
    hidden: true,
    children: [
      {
        path: '/profile/profile-index',
        component: '',
        name: 'Profile',
        meta: { title: 'Profile', icon: 'user', noCache: true, authority: ['editor'] }
      }
    ]
  },
  // {
  //   path: '/permission',
  //   component: '',
  //   redirect: '/permission/index',
  //   name: 'Permission',
  //   meta: {
  //     title: 'Permission',
  //     icon: 'lock',
  //     roles: ['admin', 'editor'] // you can set roles in root nav
  //   },
  //   children: [
  //     {
  //       path: '/permission/index',
  //       component: '',
  //       name: 'PagePermission',
  //       hidden: true,
  //       meta: {
  //         title: 'Page Permission',
  //         roles: ['admin'] // or you can only set roles in sub nav
  //       }
  //     },
  //     {
  //       path: '/permission/directive',
  //       component: '',
  //       name: 'DirectivePermission',
  //       meta: {
  //         title: 'Directive Permission'
  //         // if do not set roles, means: this page does not require permission
  //       }
  //     }
  //   ]
  // },
  {
    path: '/permission',
    component: '',
    redirect: '/permission/index',
    meta: {
        title: 'permission',
        icon: 'lock',
        authority: ['admin']
      },
    children: [
      {
        path: '/permission/index',
        component: '',
        name: 'Permission',
        meta: { title: 'Permission', icon: 'permission', affix: true,  authority: ['admin'] }
      }
    ]
  },

  {
    path: '/icon',
    component: '',
    redirect: '/icon/index',
    meta: {
        title: 'icon',
        icon: 'lock'
      },
    children: [
      {
        path: '/icon/index',
        component: '',
        name: 'Icons',
        meta: { title: 'Icons', icon: 'icon', noCache: true }
      }
    ]
  },
  chartsRouter,
  {
    path: '/external-link',
    component: '',
    meta: {
        title: 'external-link',
        icon: 'lock',
        link: true
      },
    children: [
      {
        path: 'http://www.baidu.com',
        meta: { title: 'External Link', icon: 'link' }
      }
      // {
      //   path: 'https://github.com/PanJiaChen/vue-element-admin2',
      //   meta: { title: 'External Link', icon: 'link', link: true }
      // }
    ]
  },

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true } ...constantRoutes,
]

const router = [ ...asyncRoutes]

export default router
